Query and manipulate a graph as it were an adjacency list
# S3 method for igraph
[[(x, i, j, from, to, ..., directed = TRUE, edges = FALSE, exact = TRUE)
The graph.
Index, integer, character or logical, see details below.
Index, integer, character or logical, see details below.
A numeric or character vector giving vertex ids or
names. Together with the to
argument, it can be used to
query/set a sequence of edges. See details below. This argument cannot
be present together with any of the i
and j
arguments
and if it is present, then the to
argument must be present as
well.
A numeric or character vector giving vertex ids or
names. Together with the from
argument, it can be used to
query/set a sequence of edges. See details below. This argument cannot
be present together with any of the i
and j
arguments
and if it is present, then the from
argument must be present as
well.
Additional arguments are not used currently.
Logical scalar, whether to consider edge directions in directed graphs. It is ignored for undirected graphs.
Logical scalar, whether to return edge ids.
Ignored.
The double bracket operator indexes the (imaginary) adjacency list of the graph. This can used for the following operations:
Querying the adjacent vertices for one or more vertices:
graph[[1:3,]] graph[[,1:3]]
The first form gives the successors, the second the predecessors or the 1:3 vertices. (For undirected graphs they are equivalent.)
Querying the incident edges for one or more vertices,
if the edges
argument is set to
TRUE
:
graph[[1:3, , edges=TRUE]] graph[[, 1:3, edges=TRUE]]
Querying the edge ids between two sets or vertices, if both indices are used. E.g.
graph[[v, w, edges=TRUE]]
gives the edge ids of all the edges that exist from vertices \(v\) to vertices \(w\).
The alternative argument names from
and to
can be used
instead of the usual i
and j
, to make the code more
readable:
graph[[from = 1:3]] graph[[from = v, to = w, edges = TRUE]]
‘[[
’ operators allows logical indices and negative indices
as well, with the usual R semantics.
Vertex names are also supported, so instead of a numeric vertex id a
vertex can also be given to ‘[
’ and ‘[[
’.
Other structural queries:
[.igraph()
,
adjacent_vertices()
,
are_adjacent()
,
ends()
,
get.edge.ids()
,
gorder()
,
gsize()
,
head_of()
,
incident_edges()
,
incident()
,
is_directed()
,
neighbors()
,
tail_of()